package com.ihmp.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ihmp.model.Tproductinrooms;

@Repository("productInRoomDAO")
public class ProductInRoomDAOImpl implements ProductInRoomDAO {
	@Autowired
	private SessionFactory sessionFactory;
	
	public void saveOrUpdateProductInRoom(Tproductinrooms tproductinroom){
		sessionFactory.getCurrentSession().saveOrUpdate(tproductinroom);
	}
	 
	 public Tproductinrooms getProductInRoom(Integer id){
		 return (Tproductinrooms) sessionFactory.getCurrentSession().get(Tproductinrooms.class, id);
	 }
	 
	 public void deleteProductInRoom(Tproductinrooms tproductinroom){		 
		 sessionFactory.getCurrentSession().delete(tproductinroom);
	 }
	 
	 @SuppressWarnings("unchecked") 
	 public List<Tproductinrooms> listProductInRooms(){
		 return (List<Tproductinrooms>) sessionFactory.getCurrentSession().createQuery("from Tproductinrooms p order by p.productInRoomId desc").list();
	 }
}
